package com.kb.design.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kb.design.common.ApiResponse;
import com.kb.design.common.ResponseObject;
import com.kb.design.dto.DesignCommunicateList;
import com.kb.design.dto.DesignRequirementDTO;
import com.kb.design.dto.ForestallOrderDTO;
import com.kb.design.dto.TaskCompletedDTO;
import com.kb.design.entity.DesignCommunicate;
import com.kb.design.entity.DesignResponsiblePerson;
import com.kb.design.service.DesignCommunicateService;
import com.kb.design.service.DesignRequirementServer;
import com.kb.design.service.DesignReviewService;
import com.kb.design.vo.ReviewVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Auther:chenzx
 * @Date:2023/11/13
 * @Description:需求数据
 */
@RestController
@RequestMapping("design")
public class DesignController {

    @Resource
    private DesignRequirementServer designRequirementServer;
    @Resource
    private DesignReviewService designReviewService;
    @Resource
    private DesignCommunicateService designCommunicateService;
    /**
     * 分页查询
     *
     * @param
     * @return 查询结果
     */
    @PostMapping("pageSearch")
    public ApiResponse pageSearch(@RequestBody DesignRequirementDTO designRequirementDTO) {
        Page<DesignRequirementDTO> designRequirementPage = designRequirementServer.queryByPage(designRequirementDTO);

        return ApiResponse.success(new ResponseObject(designRequirementPage.getRecords(),designRequirementPage.getTotal()));
    }


    /**
     * 任务完成
     *
     * @param
     * @return
     */
    @PostMapping("taskCompleted")
    public ApiResponse taskCompleted(@RequestBody TaskCompletedDTO taskCompletedDTO) {
        return ApiResponse.success(designRequirementServer.taskCompleted(taskCompletedDTO));
    }

    /**
     * 工作区数据查询
     *
     * @param
     * @return
     */
    @PostMapping("queryWorkData")
    public ApiResponse queryWorkData(@RequestBody TaskCompletedDTO taskCompletedDTO) {
        return ApiResponse.success(designRequirementServer.queryWorkData(taskCompletedDTO));
    }

    /**
     *
     *
     * @param
     * @return 抢单
     */
    @PostMapping("forestallOrder")
    public ApiResponse forestallOrder(@RequestBody ForestallOrderDTO forestallOrderDTO) {
        return ApiResponse.success(designRequirementServer.forestallOrder(forestallOrderDTO));
    }

    /**
     * 布局完成
     *
     * @param
     * @return
     */
    @PostMapping("submitLayout")
    public ApiResponse submitWiring(@RequestBody ForestallOrderDTO forestallOrderDTO) {
        return ApiResponse.success(designRequirementServer.submitLayout(forestallOrderDTO));
    }

    /**
     * 布线完成
     *
     * @param
     * @return
     */
    @PostMapping("submitWiring")
    public ApiResponse submitLayout(@RequestBody ForestallOrderDTO forestallOrderDTO) {
        return ApiResponse.success(designRequirementServer.submitWiring(forestallOrderDTO));
    }

    /**
     *查询审核内容
     *
     * @param
     * @return
     */
    @GetMapping("reviewContent")
    public ApiResponse reviewContent(String type) {

        return ApiResponse.success(designRequirementServer.reviewContent(type));
    }

    /**
     *提交审核
     *
     * @param
     * @return
     */
    @PostMapping("submitReview")
    public ApiResponse submitReview(@RequestBody ReviewVO reviewVO) {
        return ApiResponse.success(designReviewService.insert(reviewVO));
    }

    /**
     *已审核内容
     *
     * @param
     * @return
     */
    @PostMapping("queryReview")
    public ApiResponse queryReview(@RequestBody ForestallOrderDTO forestallOrderDTO) {
        return ApiResponse.success(designReviewService.queryReview(forestallOrderDTO));
    }
    /**
     * 回退
     *
     * @param
     * @return
     */
    @PostMapping("fallback")
    public ApiResponse fallback (@RequestBody ForestallOrderDTO forestallOrderDTO) {
        return ApiResponse.success(designRequirementServer.fallback (forestallOrderDTO));
    }
    /**
     * 查询是否有协助任务
     *
     * @param
     * @return
     */
    @PostMapping("queryAssistTask")
    public ApiResponse queryAssistTask (@RequestBody ForestallOrderDTO forestallOrderDTO) {
        DesignResponsiblePerson designResponsiblePerson = designRequirementServer.queryAssistTask(forestallOrderDTO);
        if (Objects.nonNull(designResponsiblePerson)){
            return ApiResponse.error(null);
        }
        return ApiResponse.success(null);
    }
    /**
     * 查询项目工时列表
     *
     * @param
     * @return
     */
    @PostMapping("queryWorkTimeList")
    public ApiResponse queryWorkTimeList (@RequestBody ForestallOrderDTO forestallOrderDTO ) {
        return ApiResponse.success(designRequirementServer.queryWorkTimeList(forestallOrderDTO));
    }
    /**
     * 工时确认
     *
     * @param
     * @return
     */
    @PostMapping("confirmWorkHours")
    public ApiResponse confirmWorkHours (@RequestBody Map<String,List<DesignResponsiblePerson>> map) {
        return ApiResponse.success(designRequirementServer.confirmWorkHours(map));
    }

    /**
     *问题交流新增
     *
     * @param
     * @return
     */
    @PostMapping("searchCommunicateInfo")
    public ApiResponse searchCommunicateInfo(@RequestBody DesignCommunicateList designCommunicateList){
        return ApiResponse.success(designCommunicateService.searchCommunicateInfo(designCommunicateList));
    }
    /**
     *问题交流新增
     *
     * @param
     * @return
     */
    @PostMapping("communicateInsert")
    public ApiResponse communicateInsert(@RequestBody DesignCommunicateList designCommunicateList){
            return ApiResponse.success(designCommunicateService.insert(designCommunicateList));
    }

    /**
     *问题交流更新
     *
     * @param
     * @return
     */
    @PostMapping("communicateUpdate")
    public ApiResponse communicateUpdate(@RequestBody List<DesignCommunicate> designCommunicateList){
        return ApiResponse.success(designCommunicateService.update(designCommunicateList));
    }
}
